package com.qf.j2112.controller;

import com.qf.j2112.po.Dept;
import com.qf.j2112.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class DeptController {
    @Autowired
    private DeptService deptService;
    @RequestMapping("/dept")
    public List<Dept> findAll(){
        List<Dept> all=deptService.findAllDept();
        return all;
    }
    @RequestMapping(value="/dept",method = RequestMethod.POST)
    public Dept addDept(@RequestBody Dept dept){
        Dept xdept=deptService.addDept(dept);
        return xdept;
    }
    @RequestMapping(value="/dept",method = RequestMethod.PUT)
    public Dept update(@RequestBody Dept dept){
        Dept xdept=deptService.updateDept(dept);
        return xdept;
    }
    @RequestMapping(value="/dept/{id}",method = RequestMethod.DELETE)
    public String deleteDept(@PathVariable("id") int id){
        boolean bl=deptService.deleteDept(id);
        if (bl){
            return "200";
        }else{
            return "-200";
        }
    }
}
